package service

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto/rpc"
	"api-gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddDanMu(c *gin.Context) {
	var form request.AddDanMu
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	danMu, err := config.VideoRpcClient.AddDanMu(c, &__.AddDanMuReq{
		UserId:    form.UserId,
		VideoId:   form.VideoId,
		EpisodeId: form.EpisodeId,
		Duration:  form.Duration,
		Content:   form.Content,
		Color:     form.Color,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "发送弹幕完成", "data": gin.H{
		"danmu": danMu.DanMuId,
	}})
	return
}

func GetDanMu(c *gin.Context) {
	var form request.GetDanMu
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	danMu, err := config.VideoRpcClient.GetDanMu(c, &__.GetDanMuReq{
		UserId:    form.UserId,
		VideoId:   form.VideoId,
		EpisodeId: form.EpisodeId,
		Duration:  form.Duration,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "获取弹幕成功", "data": gin.H{
		"danMuList": danMu.List,
	}})
	return
}
